package com.phf.vhr.mapper;

import com.phf.vhr.model.entity.RolesDO;
import com.phf.vhr.model.entity.UsersRolesDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户角色表 Mapper 接口
 * </p>
 *
 * @author phf
 * @since 2021-09-26
 */
@Mapper
public interface UsersRolesMapper extends BaseMapper<UsersRolesDO> {

    /**
     * 通过 用户id 获取 角色
     * 
     * @param userId 用户id
     * @return
     */
    @Select("select (SELECT `name` FROM roles WHERE roles.id = users_roles.roles_id ) AS `name` from users_roles where users_id =  #{userId}")
    List<RolesDO> getUserRolesStringByUserId(Long userId);

    @Select("select * from users_roles where users_id  = #{userId}")
    List<UsersRolesDO> getUserRolesListByUserId(Long userId);

}
